const CompressionPlugin = require("compression-webpack-plugin");
const webpack = require("webpack");

// const URL_BASE =
//   process.env.NODE_ENV === "production"
//     ? "http://47.92.27.141:8899"    10.1.13.5:8666
//     : "http://47.92.27.141:8899";
    const URL_BASE =
    process.env.NODE_ENV === "production"
      ? "http://10.1.13.5:8666"
      : "http://10.1.13.5:8666";
// const URL_BASE =
//   process.env.NODE_ENV === "production"http://47.92.27.141:8666/
//     ? "http://10.1.13.14:8899"
//     : "http://10.1.13.14:8899";
const URL_ONE = "http://10.39.5.120:9797"; //财务暂时未用
module.exports = {
  devServer: {
    host: "0.0.0.0",
    port: 8899,
    publicPath: "/",
    disableHostCheck: true,
    proxy: {
      "/xboot": {
        target: URL_BASE, // 请求本地 需要xboot后台项目
        ws: true,
      },
      "/loginTest": {
        target: URL_BASE,
        ws: true,
        pathRewrite: {
          "^/loginTest": "/loginTest",
        },
      },
      "/portal": {
        target: URL_ONE,
        ws: true,
        pathRewrite: {
          "^/portal": "/portal",
        },
      },
      "/ssoLogin": {
        target: URL_BASE,
        ws: true,
        pathRewrite: {
          "^/ssoLogin": "/ssoLogin",
        },
      },
      "/hnPortalApp": {
        target: URL_BASE,
        ws: true,
        pathRewrite: {
          "^/hnPortalApp": "/hnPortalApp",
        },
      },
      "/qrcode": {
        target: URL_BASE,
        ws: true,
        pathRewrite: {
          "^/qrcode": "/qrcode",
        },
      },
      "/websocket": {
        target: URL_BASE,
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/websocket": "",
        },
      },
    },
  },
  // 打包时不生成.map文件 避免看到源码
  productionSourceMap: false,
  // 部署优化
  configureWebpack: {
    // 使用CDN
    externals: {
      vue: "Vue",
      axios: "axios",
      "vue-router": "VueRouter",
      vuex: "Vuex",
      "js-cookie": "Cookies",
      iview: "iview",
      "vue-i18n": "VueI18n",
      "vue-lazyload": "VueLazyload",
      countup: "countUp",
      "date-fns": "format",
      html2canvas: "html2canvas",
      quill: "Quill",
      echarts: "echarts",
      apexcharts: "ApexCharts",
      "vue-apexcharts": "VueApexCharts",
      xlsx: "XLSX",
      // dplayer: 'DPlayer',// "dplayer": "^1.25.0",
    },
    // GZIP压缩
    plugins: [
      new CompressionPlugin({
        test: /\.js$|\.html$|\.css/, // 匹配文件
        threshold: 10240, // 对超过10k文件压缩
      }),
      new webpack.ProvidePlugin({}),
    ],
  },
};
